package entity;

import java.util.Calendar;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Entity @Table(name="TREATMENT_ACTS")
@NamedQuery(name = "TreatmentAct.selectByClientId", query = "SELECT t FROM TreatmentAct t WHERE t.client.id = :id ORDER BY t.appealDate DESC")
public class TreatmentAct {
	
	@Id
	@Column(name = "ACT_ID")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DEF_GEN")    
	@SequenceGenerator(name = "DEF_GEN", sequenceName = "ACT_ID_SEQ", allocationSize=1)
    private int id;
	
    @NotNull(message="Appeal date cannot be empty")
	@Temporal(TemporalType.TIMESTAMP)    
	@Column(name = "APPEAL_DATE") 
	private Calendar appealDate;
	
    @NotNull(message="Symptoms field cannot be empty")
    @Size(min=6, max=200, message="Length must be in 6 and 200 characters") 
    @Pattern(regexp = "^\\S.+$", message = "{must.contain.only.letters.or.numbers}")
	@Column(name = "SYMPTOMS") 
	private String symptoms;
	
    @NotNull(message="Diagnosis cannot be empty")
    @Size(min=3, max=30, message="Diagnosis length must be in 3 and 30")
	@Column(name = "DIAGNOSIS") 
	private String diagnosis;
	
	@Column(name = "PAID_STATUS", nullable = false) 
	private boolean paidStatus;
	
	@ManyToOne
	@JoinColumn(name = "CLIENT_ID", nullable = false)
	private Client client;
	
	@OneToMany(mappedBy = "act", cascade = CascadeType.REMOVE)
    private Set<TreatmentRequest> requests;
	
	public TreatmentAct() {
		diagnosis = "Unknown";
	}
	
	public TreatmentAct(Calendar appealDate, String symptoms, boolean paidStatus, Client client) {
		this.appealDate = appealDate;
		this.symptoms = symptoms;
		this.paidStatus = paidStatus;
		this.client = client;
	}
	
	public int getId() {
        return id;
    }
 
    public void setId(int id) {
        this.id = id;
    }

	public Calendar getAppealDate() {
		return appealDate;
	}

	public void setAppealDate(Calendar appealDate) {
		this.appealDate = appealDate;
	}

	public String getSymptoms() {
		return symptoms;
	}

	public void setSymptoms(String symptoms) {
		this.symptoms = symptoms;
	}

	public String getDiagnosis() {
		return diagnosis;
	}

	public void setDiagnosis(String diagnosis) {
		this.diagnosis = diagnosis;
	}

	public boolean isPaidStatus() {
		return paidStatus;
	}

	public void setPaidStatus(boolean paidStatus) {
		this.paidStatus = paidStatus;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}
	
}
